package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.GoodsType;
import com.atguigu.jxc.entity.GoodsTypeVo;
import com.atguigu.jxc.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 获取全部类别
     *
     * @return
     */
    @PostMapping("/loadGoodsType")
    public List<GoodsTypeVo> goodsType() {
        List<GoodsTypeVo> map=goodsService.getGoodstypes();
        System.out.println(JSON.toJSONString(map));
        return map;
    }


    /**
     * 增加类别
     *
     * @return
     */
    @PostMapping("/save")
    public ServiceVO save(String  goodsTypeName,Integer  pId) {
        goodsService.save(goodsTypeName,pId);
        return  new ServiceVO(100,"增成功了");
    }

    /**
     * 增加类别
     *
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(Integer  goodsTypeId) {
        goodsService.delete(goodsTypeId);
        return  new ServiceVO(100,"增成功了");
    }

}


